package PriorityQueue;

public class PriorityQueue {
    public int []arr;
    public int us;
    public PriorityQueue(){
        this.arr=new int[10];
    }
    public void InitArr(int []array){
        for (int i = 0; i < array.length; i++) {
            this.arr[i]=arr[i];
            this.us++;
        }
    }
    public void createHeap(){
        for (int parent=(this.us-1-1)/2; parent>=0;us--) {
            sitDowm(parent,this.us);
        }
    }
    public void sitDowm(int parent,int us){
        int chird=2*parent+1;
        while(chird<us){
            if(chird+1<us&&arr[chird]<arr[chird+1]){
                chird++;
            }
            if(arr[chird]>arr[parent]){
                swap(arr,chird,parent);
                parent=chird;
                chird=2*parent+1;
            }else {
                break;
            }
        }
    }
    public  void swap(int[] arr,int i,int j){
        int tmp=arr[i];
        arr[i]=arr[j];
        arr[j]=tmp;
    }
}
